<template>
  <div>
  <div>home page</div>
    <div v-if="state.username">
   <div>昵称:{{state.nickname}}</div>
    <div>用户名:{{state.username}}</div>
    <div>用户ID:{{state.userid}}</div>
    </div>
  </div>
</template>

<script>
import { apiHome} from '../api/api'
import { reactive} from "vue";
export default {
  name: "Home",

  setup() {
    //保存用户数据的变量
    const state = reactive({});
    //从接口获取用户信息
    const home = async () => {
      apiHome({
      }).then(res => {
        //成功
        if (res.code == 0) {
            Object.assign(state, res.data);
        }
      }).catch((error) => {
        console.log(error)
      })
    };
    home();
    return {
      home,
      state,
    };
  }

}
</script>

<style scoped>

</style>